package com.jl.smartcard.ui.views.project;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;


public class TreeFolder extends TreeFile{
	private ArrayList<TreeFile> children;

	public TreeFolder(File path) {
		super(path);
		children = new ArrayList<TreeFile>();
	}

	public void addChild(TreeFile child) {
		File f = child.getFile();
		if(!f.exists()){
			try {
				if(child instanceof TreeFolder){
					f.mkdir();
				}else{
					f.createNewFile();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		children.add(child);
		child.setParent(this);
	}

	public void removeChild(TreeFile child) {
		children.remove(child);
		child.setParent(null);
	}

	public TreeFile[] getChildren() {
		return children.toArray(new TreeFile[children.size()]);
	}

	public boolean hasChildren() {
		return children.size() > 0;
	}
}
